Imports KanBan.Pgd.Infrastructure.Exceptions
Imports KanBan.Pgd.Domain
Imports KanBan.Pgd.Domain.Entities
Imports KanBan.Pgd.Presentation.Controllers
Imports KanBan.Pgd.Presentation.Views
Imports KanBan.Pgd.Infrastructure.Report
Imports KanBan.Pgd.Infrastructure.Repositories

Public Class ReportOptions

    Public Sub New(ByVal type As DomainEntities, ByVal displayName As String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        Me.EntityType = type
        Me.FormTitle = String.Format("Generate Report for: {0}", displayName)

    End Sub

    Public Sub Export()

        Dim path As String

        Select Case Me.EntityType
            Case DomainEntities.SearchRequest
                Dim repository As New SearchRequestRepository()
                path = repository.GenerateReport(Me.FromDate, Me.ToDate)
            Case Else
                path = String.Empty
        End Select

        If Not String.IsNullOrEmpty(path) Then
            Process.Start(path)
        Else
            Dim errorList As New List(Of ApplicationError)
            errorList.Add(New ApplicationError("ReportError", "There's been an error while creating the Report"))
            'MyBase.ShowError(errorList)
        End If

    End Sub


    Public Property FormTitle() As String
        Get
            Return txtFormTitle.Text
        End Get
        Set(ByVal value As String)
            txtFormTitle.Text = value
        End Set
    End Property

    Private _entityType As DomainEntities
    Public Property EntityType() As DomainEntities
        Get
            Return _entityType
        End Get
        Set(ByVal value As DomainEntities)
            _entityType = value
        End Set
    End Property

    Public Property FromDate() As DateTime
        Get

            Dim year As Integer = dtpFromDate.Value.Year
            Dim month As Integer = dtpFromDate.Value.Month
            Dim day As Integer = dtpFromDate.Value.Day

            Return New Date(year, month, day)

        End Get
        Set(ByVal value As DateTime)
            dtpFromDate.Value = value
        End Set
    End Property

    Public Property ToDate() As DateTime
        Get

            Dim year As Integer = dtpToDate.Value.Year
            Dim month As Integer = dtpToDate.Value.Month
            Dim day As Integer = dtpToDate.Value.Day

            Return New Date(year, month, day)

        End Get
        Set(ByVal value As DateTime)
            dtpToDate.Value = value
        End Set
    End Property

    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Me.Export()
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class